/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.capex.javaee.applets;

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class Mylist extends Applet implements ActionListener, ItemListener {

    private List colorlist;
    private String colorNames[] = {"Black", "Blue", "Cyan", "Dark Gray", "Gray", "Green", "Magneta", "Orange"};
    private Color colors[] = {Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.magenta, Color.orange};

    @Override
    public void init() {
        colorlist = new List(5, false);
        colorlist.addActionListener(this);
        colorlist.addItemListener(this);
        for (int i = 0; i < colorNames.length; i++) {
            colorlist.add(colorNames[i]);
        }
        add(colorlist);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        setBackground(colors[colorlist.getSelectedIndex()]);
        repaint();
    }

    @Override
    public void itemStateChanged(ItemEvent e) {
        showStatus(colorlist.getSelectedItem() + "index" + colorlist.getSelectedIndex());
    }
}
